package com.gtp.kafka.producer;

import java.util.HashMap;
import java.util.Map;

import org.apache.kafka.clients.producer.KafkaProducer;

import com.gtp.kafka.KafkaConstants;

public abstract class BaseProducer {
	
	protected KafkaProducer<String, String> producer;

	
	public BaseProducer(){
		producer=new KafkaProducer<String, String>(baseConfigs());
	}
	
	private Map<String,Object> baseConfigs() {
		
		Map<String,Object> props=new HashMap<String,Object>();
		props.put("bootstrap.servers", KafkaConstants.servers);
		props.put("value.serializer", "org.apache.kafka.common.serialization.StringSerializer");
		props.put("key.serializer", "org.apache.kafka.common.serialization.StringSerializer");
		
		//允许子类自定义
		customConfigs(props);
		
		return props;
	}
	
	protected void customConfigs(Map<String,Object> configs){
		//子类可选择性扩展
	}
}
